#ifndef CLIENT_PROCESSOR_H_
#define CLIENT_PROCESSOR_H_

#include "rpc/rpc_process.h"
#include "include/rpc_def.h"

namespace urpc {
class EventManager;
struct Event;
class Connection;
class Protocol;

class ClientProcessor : public RpcProcessor {
  public:
    struct RpcRequestInfo {
        uint32 rpc_id;
        uint32 func_id;
        const MethodDescriptor* method;
        RpcController* controller;
        const Message* request;
        Message* response;
        google::protobuf::Closure* done;
    };

    ClientProcessor(EventManager* event_manager)
        : event_manager_(event_manager) {
    }

    void SetConnection(Connection* conn);

    void CallMethod(RpcRequestInfo* info);

    void StopStream() {
    }

    void HandleRead(Connection* conn, Buffer* buf);

  private:
    Mutex conn_mutex_;
    scoped_ptr<Connection> conn_;
    EventManager* event_manager_;

    scoped_ptr<Protocol> protocol_;
    scoped_ptr<ClientProcessor> processor_;

    Mutex req_mutex_;
    std::map<uint32, RpcRequestInfo*> req_map_;

    bool SendRequest(RpcRequestInfo* info);

    DISALLOW_COPY_AND_ASSIGN(ClientProcessor);
};
}

#endif
